<template>
  <div class="app-container">
    <header>
      <div>
        <el-form inline  class="demo-form-inline" size="small" label-width="140px">
          <el-form-item label="驾校名称" label-width="70px">
            <el-input v-model="params.name" placeholder="请输入驾校名称或ID" @keyup.enter.native="getDschool"/>
          </el-form-item>
          <el-form-item label="城市">
             <el-select v-model="params.cityCode" placeholder="不限" @change="changeSlect" clearable>
                <el-option :label="c.areaName" :value="c.areaCode" v-for="(c, index) in cityArr" :key="index" />
              </el-select>
          </el-form-item>
          <el-form-item label="维护费选项">
            <el-select v-model="params.needfee" placeholder="请选择是否收取维护费" clearable @change="needfeeChange"> 
              <el-option label="需要收取" value="1" />
              <el-option label="无需收取" value="0" />
            </el-select>
          </el-form-item>
          <el-form-item label="维护费开始日期">
            <el-date-picker v-model="svdate" type="date" value-format="yyyy-MM-dd" @change="svdateChange" />
          </el-form-item>
          <el-form-item label="维护费截止日期">
            <el-date-picker v-model="evdate" type="date" value-format="yyyy-MM-dd" @change="evdateChange" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="getDschool">查询</el-button>
            <el-button type="primary" icon="el-icon-plus" @click="$oldLoginSystem('http://jx.qida999.com/DriverCommon/system/DrJx.aspx?JxID=0')">新增</el-button>
            <el-button type="info" plain @click="$oldLoginSystem('http://jx.qida999.com/DriverCommon/driver/dr_delmark.html')">归档学员管理</el-button>
            <el-button type="info" plain>重置JSON静态配置文件</el-button>
          </el-form-item>

        </el-form>
      </div>
    </header>
    <main>
      <div style="height: 650px;">
        <el-table :data="tableData" stripe border style="width: 100%" height="100%">
          <el-table-column fixed prop="JxID" label="ID" width="150" align="center">
            <template slot-scope="scope">
              <span style="color: #4d4de2;cursor: pointer;"
                @click="go(scope.row, 'http://jx.qida999.com/DriverCommon/system/DrJx.aspx')">{{
                  scope.row.JxID }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="city" label="城市名称" width="150" align="center" />
          <el-table-column prop="jxName" label="驾校名称" width="180" align="center" />
          <el-table-column prop="cnt" label="账号数" width="150" align="center">
            <template slot-scope="scope">
                <span style="color: #4d4de2;cursor: pointer;"
                  @click="go(scope.row, 'http://jx.qida999.com/DriverCommon/system/DrJx.aspx')">{{
                    scope.row.cnt }}</span>
              </template>
          </el-table-column>
          <el-table-column prop="JxImgCnt" label="附件数" width="150" align="center" />
          <el-table-column prop="person" label="联系人" width="150" align="center" />
          <el-table-column prop="tel" label="电话" width="150" align="center" />
          <el-table-column prop="editer" label="修改人" width="150" align="center" />
          <el-table-column prop="edittime" label="修改日期" width="220" align="center" />
          <el-table-column prop="firster" label="建立人" width="150" align="center" />
          <el-table-column prop="firsttime" label="建立日期" width="220" align="center" />
          <el-table-column prop="ep" label="备注" width="150" align="center" />
          <el-table-column label="操作" width="120" fixed="right" align="center">
            <template slot-scope="scope">
              <el-button type="danger" plain size="mini" class="el-icon-delete" @click="deleteHandler(scope.$index, scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </main>
    <!-- 分页 -->
    <div class="pagin">
      <el-pagination background :current-page="params.page" :page-sizes="[20, 50, 100, 150]"
        layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="handleSizeChange"
        @current-change="handleCurrentChange" :page-size="params.pageSize" />
    </div>
  </div>
</template>

<script>
import { adminAPI } from '@/api/adminstare'

/**
* @author        Yng
* @time          2023-10-28 15:03:03  星期六
* @description   驾校管理
**/

export default {
  name:'DschoolManage',
  data() {
    return {
      tableData: [],
      params: {
        action: 'drJxList',
        page: 1,
        pageSize: 20,
        cityCode: '不限',//城市code
        needfee: '不限',//维护费选项，不限/1/0,三者取其一， 1-需要收取，0-无需收取
        name: '',//驾校ID/驾校名称，模糊查询
        svdate: '',//下次维护费日期开始
        evdate: '',//下次维护费日期截止
      },
      total: 0,
      cityArr: [],//城市列表
      svdate: '',//下次维护费日期开始
      evdate:'',//下次维护费日期截止
    }
  },
  async mounted() {
    this.getDschool()

    // 获取城市列表
    this.cityArr= this.$store.state.commonData.cityArr
    if (this.cityArr.length < 1) { 
      const result = await this.$store.dispatch('commonData/getCityList')
      this.cityArr=result
    }
  },
  methods: {
    // 城市列表code值
    changeSlect(AddressVal) {
      AddressVal=="" ? AddressVal='不限' : AddressVal
      this.params.cityCode = AddressVal
      this.getDschool()
    },
    // 维护费下拉选项发生变化
    needfeeChange(e) { 
      e == "" ? e = '不限' : e
      this.params.needfee = e
      this.getDschool()
    },
    // 在线用户数据
    async getDschool() {
      // 为了解决日期为null查询不了的问题！！！！
      if (this.svdate) this.params.svdate = this.svdate
      if(this.evdate) this.params.evdate = this.evdate

      let { code, data, total } = await adminAPI(this.params)
      if (!code) {
        this.tableData = data
        this.total = total
      }
    },
    // 一页几条数据
    handleSizeChange(val) {
      this.params.pageSize = val
      this.getDschool();
    },
    // 当前页
    handleCurrentChange(val) {
      this.params.page = val
      this.getDschool();
    },
    //维护费开始日期
    svdateChange(e) {
      this.svdate = e == null ? ' ' : e
      this.getDschool()
    },
    // 维护费日期截止
    evdateChange(e) { 
      this.evdate = e == null ? ' ' : e
      this.getDschool()
    },
    go(val, URL) {
      let redirectUrl= `${URL}?JxID=${val.JxID}`
      this.$oldLoginSystem(redirectUrl)
    },
    // 删除
    deleteHandler(index, row) { 
      this.$confirm('此操作将永久账号, 是否继续?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        adminAPI({ action: 'drJxDelete', toDeleteJxID: row.JxID }).then(res => {
          this.getDschool()
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        })
      })


      
    }
  }
}
</script>

<style lang="scss" scoped>
.app-container {
  background-color: white;

  main {
    &>div {
      height: 600px;
    }
  }
}
</style>
